﻿using System;
using System.Collections.Generic;
using System.Net;
using Platformer_Example.Controller.Network.Messages;
using Transformable_Engine_v2.Engine.Global;

namespace Platformer_Example.Controller.Network
{
    public class ServerSummaryData
    {
        public IPAddress Address { get; set; }
        public SearchGameResponse Description { get; set; }
    }

    public class ClientData
    {
        public List<ServerSummaryData> ServerList { get; private set; }

        private Guid? _id;
        public Guid Id
        {
            get { return (Guid) _id; }
        }
        public void SetNetworkId(string id)
        {
            if (_id == null)
                _id = Guid.Parse(id);
        }

        public IPAddress ServerIPAddress { get; private set; }
        public void SelectServer(int id)
        {
            ServerIPAddress = ServerList[id].Address;
            ServerList.Clear();
        }

        public void AddServer(IPAddress address, SearchGameResponse response)
        {
            Log.LogInfo("(" + ServerList.Count + ") Server " + address + " - " + response);
            ServerList.Add(new ServerSummaryData
                               {
                                   Address = address,
                                   Description = response
                               });
        }

        public void RefreshServers()
        {
            ServerList = new List<ServerSummaryData>();
        }
    }
}